'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 等级排行 
 * @author sundbcn@gmail.com (sun debing)
 */

var async = require('async');
var _ = require('lodash');
var Code = require('../../../../consts/code');
var surviveService = require('../../../../services/surviveService');

module.exports = function (msg, session, next) {
    var role_id = session.uid;

    var current_role_info = {};
    var top_fifty_role = [];
    async.waterfall(
        [
            function (cb) {
                surviveService.currentRoleRank(role_id, cb);
            },
            function (role_info, cb) {
                current_role_info = role_info;
                surviveService.rank(cb);
            },
            function (role_info_list, cb) {
                top_fifty_role = role_info_list;
                cb();
            }
        ],
        function (err) {
            if (!!err) {
                console.error(err);
                return next(null, {
                    code: Code.FAIL
                });
            }
            return next(null, {
                code: Code.OK,
                result: {
                    current_role_info: current_role_info,
                    top_fifty_role: top_fifty_role
                }
            });
        }
    );
};
